//
//  ToolViewController.m
//  XhlTrip
//
//  Created by dllo on 15/8/21.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "ToolViewController.h"
#import "CusNaviView.h"
#import "NightSingleton.h"
#import "CollectionViewController.h"
#import "RemoveCache.h"
#import "SearchViewController.h"

NSInteger y = 1;
@interface ToolViewController ()
@property (nonatomic, retain) RemoveCache *remove;

@end

@implementation ToolViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

/* 夜间模式按钮 */
- (void)createButton
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(80 * Width, 70 * Height, 200 * Width, 50 * Height);
    [button addTarget:self action:@selector(nightButton:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"开启夜间模式" forState:UIControlStateNormal];
    button.layer.cornerRadius = 7;
    button.layer.borderColor = [UIColor whiteColor].CGColor;
    button.layer.borderWidth = 1;
    [self.view addSubview:button];
    
    UIButton *collectbutton = [UIButton buttonWithType:UIButtonTypeSystem];
    collectbutton.frame = CGRectMake(80 * Width, 140 * Height, 200 * Width, 50 * Height);
    [collectbutton addTarget:self action:@selector(collectbutton:) forControlEvents:UIControlEventTouchUpInside];
    [collectbutton setTitle:@"查看我的收藏" forState:UIControlStateNormal];
    collectbutton.layer.cornerRadius = 7;
    collectbutton.layer.borderColor = [UIColor whiteColor].CGColor;
    collectbutton.layer.borderWidth = 1;
    [self.view addSubview:collectbutton];
    
    
    UIButton *deletebutton = [UIButton buttonWithType:UIButtonTypeSystem];
    deletebutton.frame = CGRectMake(80 * Width, 210 * Height, 200 * Width, 50 * Height);
    [deletebutton addTarget:self action:@selector(deletebutton:) forControlEvents:UIControlEventTouchUpInside];
    [deletebutton setTitle:@"清除缓存文件" forState:UIControlStateNormal];
    deletebutton.layer.cornerRadius = 7;
    deletebutton.layer.borderColor = [UIColor whiteColor].CGColor;
    deletebutton.layer.borderWidth = 1;
    [self.view addSubview:deletebutton];
    
    
    UIButton *seaarchbutton = [UIButton buttonWithType:UIButtonTypeSystem];
    seaarchbutton.frame = CGRectMake(80 * Width, 280 * Height, 200 * Width, 50 * Height);
    [seaarchbutton addTarget:self action:@selector(seaarchbutton:) forControlEvents:UIControlEventTouchUpInside];
    [seaarchbutton setTitle:@"点击进入搜索" forState:UIControlStateNormal];
    seaarchbutton.layer.cornerRadius = 7;
    seaarchbutton.layer.borderColor = [UIColor whiteColor].CGColor;
    seaarchbutton.layer.borderWidth = 1;
    [self.view addSubview:seaarchbutton];

    
    
    
}

- (void)seaarchbutton:(UIButton *)button
{
    SearchViewController *search = [[SearchViewController alloc] init];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"搜索";
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    self.navigationItem.backBarButtonItem = backItem;
    [backItem release];
    [self.navigationController pushViewController:search animated:YES];
    [search release];
}

- (void)deletebutton:(UIButton *)button
{
    self.remove = [[[RemoveCache alloc] init] autorelease];
    NSString *kk = [NSString stringWithFormat:@"%@%.2f%@", @"缓存大小为", [self.remove returnfloat], @"M,确定清理"];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:kk delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    
    [alert show];
    [alert release];
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
   
    switch (buttonIndex) {
        case 0:
            break;
            
        default:
            // 移除缓存
            [self.remove removeCache];
            break;
    }
}
- (void)collectbutton:(UIButton *)button
{
    CollectionViewController *collect = [[CollectionViewController alloc] init];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"收藏";
     [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    self.navigationItem.backBarButtonItem = backItem;
    [backItem release];
    [self.navigationController pushViewController:collect animated:YES];
    [collect release];
    
}

- (void)nightButton:(UIButton *)button
{
    NightSingleton *nightS = [NightSingleton defaultSingle];
    if (y == 1) {
        [button setTitle:@"关闭夜间模式" forState:UIControlStateNormal];
        [nightS nightopenY:YES];
        y = 2;
        
    } else if ( y == 2){
        [button setTitle:@"开启夜间模式" forState:UIControlStateNormal];
        [nightS nightopenY:NO];

        y = 1;
    }
}
- (void)dealloc
{
    [_remove release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBarController.tabBar.hidden = NO;
    self.view.backgroundColor = [UIColor colorWithPatternImage:[self nameWithPath:@"view.png"]];
#pragma mark - 头部标题栏
    [self changeNaviBar];
    
    
    [self createButton];
}
- (void)changeNaviBar
{
#pragma mark - 头部标题栏navigationBar
    
    self.navigationController.navigationBar.translucent = NO;
    CusNaviView *titleview = [[CusNaviView alloc] initWithFrame:CGRectMake(10 * Width, 0, self.navigationController.navigationBar.frame.size.width - 20 * Width, self.navigationController.navigationBar.frame.size.height)];
    self.navigationItem.titleView = titleview;
    [titleview release];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"view.png"]forBarMetrics:UIBarMetricsDefault];

    
}

- (UIImage *)nameWithPath:(NSString *)paths
{
    NSString *path = [[NSBundle mainBundle] pathForResource:paths ofType:nil];
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    return image;
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
